<?php 
if (! defined('BASEPATH')) {
	exit('Access Denied');
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>文章关键词管理</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/static/css/admin/base.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/static/css/admin/page.css">
<link rel="stylesheet" href="<?php echo base_url();?>/static/js/editor/themes/default/default.css" />

<script src="<?php echo base_url();?>/static/js/jquery.js" language="javascript"></script>

<script src="<?php echo base_url();?>/static/js/validate/validator.js" language="javascript"></script>
<script type="text/javascript">
$(document).ready(function() {

	$("#btnSave").click(function(){
		if($("#newform").Valid() == false || !$("#newform").Valid()) return false;
		var tagname = $("#tagname").val();
		var url="<?php echo site_url("admin/archive/index/archive_add");?>";
	
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=tagsadd&tagname="+tagname,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			
			if(code >0){
				common_request(1);
			}
		   },
		   beforeSend:function(){
			  
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});
	});
	common_request(1);
});

function common_request(page){
		var url = "<?php echo site_url("admin/archive/index/archive_add");?>";
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=tagslist&page="+page,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			
			
			filldata(msg.resultinfo.list.result,msg.resultinfo.list.page_string);
		   },
		   beforeSend:function(){
			  $("#result_p").html("<font color='red'>正在查询数据请稍候......</font>");
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});
		
}

function filldata(data,page_string){
	var shtml = '' ;
	if(data){
		for(var j in data){
			shtml+='<tr bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor=\'#FCFDEE\';" onmouseout="javascript:this.bgColor=\'#FFFFFF\'" id="list_tr_'+data[j]['id']+'">';
			shtml+='<td align="center">'+data[j]['id']+'</td>';
			shtml+='<td align="center" onclick="edit('+data[j]['id']+',this)" id="tr_td_'+data[j]['id']+'">'+data[j]['tagname']+'</td>';
			shtml+='<td align="center">'+data[j]['addtime']+'</td>';
			shtml+='<td align="center">'+data[j]['addperson']+'</td>';
			shtml+='<td align="center"><img src="<?php echo base_url();?>/static/image/admin/gtk-del.png" onclick="del_('+data[j]['id']+')"></td>';
			shtml+='</tr>';
		}
	}
	
	$("#result_p").html(shtml);
	$("#mynew_page").html(page_string);
}

function ajax_data(page){
	common_request(page);
}
function del_(id){
	if(!confirm('是否确定删除记录是'+id)){
		return false ;
	}
	
		var url = "<?php echo site_url("admin/archive/index/archive_add");?>";
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=del_tag&id="+id,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){//无权限
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			//删除成功
			$("#list_tr_"+id).remove();			
		   },
		   beforeSend:function(){
			
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});	
}

//编辑 关键词
function edit(id,o){
if($("#text_"+id).length<=0){
	var v  = o.innerHTML ;
	o.innerHTML = '' ;
	
	$("#tr_td_"+id).append("<input type='text' id='text_"+id+"' value="+v+" onblur=\"do_edit("+id+",\'"+v+"\')\">");
	$("#text_"+id).focus();
}

}
//处理编辑
function do_edit(id,oldtagname){
		var tagname = $("#text_"+id).val();
		if(oldtagname == tagname){
			$("#tr_td_"+id).html(oldtagname);
			return  ;
		}
		if(tagname == ''){
			return ;
		}
		var url = "<?php echo site_url("admin/archive/index/archive_add");?>";
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=edit_tag&id="+id+"&tagname="+tagname,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){//无权限
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			//删除成功
			$("#tr_td_"+id).html($("#text_"+id).val());
		   },
		   beforeSend:function(){
			
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});		
	
	
}
//生成缓存
function make_tags_cache(){
		var url = "<?php echo site_url("admin/archive/index/archive_add");?>";
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=cache_tags",
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){//无权限
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			
			alert(msg.resultinfo.errmsg);
			$("#make_tags_cache").show();
			$("#loadding").hide();
		   },
		   beforeSend:function(){
			$("#make_tags_cache").hide();
			$("#loadding").show();
			
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});		
}
</script>
</head>
<body leftmargin="8" topmargin="8">
<div class="nav_des">
<span class="des">文章关键词>></span>
	<a href="<?php echo site_url("admin/archive/index/archive_list");?>">文章管理</a>
	<a href="<?php echo site_url("admin/archive/index/archive_add");?>" >文章添加</a>
	<a href="<?php echo site_url("admin/archive/index/archive_add");?>?action=tags" class="nav_des_hover">文章关键词</a>
</div>

<!--  内容列表   -->
<form id="newform">
<input type="hidden" value="tagsadd" name="action">
<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">

<tr align="" bgcolor="#FAFAF1" height="22">
	<td >关键词<input type="text" name="tagname" class="form_input"  required="true" errmsg="请输入60个字符之内" tip="请输入60个字符之内" style="width:300px" id="tagname"> </td>
</tr>
<tr bgcolor="#FAFAF1">
<td height="28" colspan="">
	&nbsp;

	<input type="button" value="提&nbsp;&nbsp;交" class="coolbg" id='btnSave'>
</td>
</tr>

</table>

</form>


<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
<tr bgcolor="#E7E7E7">
	<td height="24" colspan="10" >&nbsp;关键词列表&nbsp;&nbsp;&nbsp;<strong style="color:red">提示:鼠标点击关键词进行编辑处理</strong></td>
</tr>
<tr align="center" bgcolor="#FAFAF1" height="22">
	<td width="6%">ID</td>
	
	<td width="20%">关键词</td>
	<td width="20%">添加时间</td>
	<td width="10%">添加人</td>
	<td width="10%">操作</td>
	
</tr>
<tbody id="result_p">

</tbody>

<tr align="right" bgcolor="#EEF4EA">

	<td height="36" colspan="5" align="right" id="mynew_page">
	
	<!--翻页代码 -->
	</td>
</tr>


<tr align="right" bgcolor="#FCFDEE">

	<td height="36" colspan="5" align="center" id="">
		<img src="<?php echo base_url();?>/static/image/admin/loadding.gif" style="display:none" id="loadding">
		<input type="button" id="make_tags_cache" value="生成关键词缓存" onclick="make_tags_cache()">
	</td>
</tr>


</table>
</body>
</html>